package game.seungha;

import util.seungha.EffectView;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.TextView;

public class Activity_Result extends Activity 
{
	final long ONE_SEC	= 1000;
	final long ONE_MIN	= ONE_SEC*60;
	final long ONE_HOUR	= ONE_MIN*60;
	final long ONE_DAY	= ONE_HOUR*24;
	
	Resources mResources;
	Activity mActivity;
	
	TextView 	mTextView_Finish;
	EffectView	mEffectView;
	
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_result);
        
        mActivity	= this;
        mResources	= mActivity.getResources();


        this.setView_Title();
        this.setView_Name();
        this.setView_Level();
        this.setView_Time();
        this.setView_Incorrect();
        
    }
    
    public void onStart()
    {
    	super.onStart();
    	mEffectView.start();
    }  

    protected void onStop() 
    {
        super.onStop();
        mEffectView.cancel();
    }    

  
    public boolean onKeyDown(int keyCode, KeyEvent event) 
    {
    	Log.i("DBG", "[Activity_Result]onKeyDown"+" event:"+event+" keyCode:"+keyCode);
    	
    	if(keyCode == KeyEvent.KEYCODE_BACK)
    	{
    		Intent intent = this.getIntent();
    		this.setResult(RESULT_CANCELED, intent);
    	}
    	
        return super.onKeyDown(keyCode, event);
    }


    
    
    public void setView_Title()
    {
    	mTextView_Finish = (TextView)this.findViewById(R.id.Result_TextView_Finish);
    	 
    	mEffectView = new EffectView(this.mTextView_Finish, Color.YELLOW);
    	mEffectView.start();
    }
    
    public void setView_Name()
    {
    	TextView nameView = (TextView) this.findViewById(R.id.Result_TextView_Name);
    	nameView.setText("Seung-Ha");
    	
    }
    
    public void setView_Level()
    {
    	String strLevel;
    	NGInfo gameInfo = NGInfo.getInstance();
    	
    	TextView levelView = (TextView) this.findViewById(R.id.Result_TextView_Level);
    	
		switch(gameInfo.getLevel())
		{
			
			case NG.LEVEL_EASY:
			{
				levelView.setText(mResources.getString(R.string.str_com_level_easy));
				levelView.setTextColor(mResources.getColor(R.color.easy));
				break;
			}
			case NG.LEVEL_NORMAL:
			{
				levelView.setText(mResources.getString(R.string.str_com_level_normal));
				levelView.setTextColor(mResources.getColor(R.color.normal));
				break;
			}
			case NG.LEVEL_HARD:
			{
				levelView.setText(mResources.getString(R.string.str_com_level_hard));
				levelView.setTextColor(mResources.getColor(R.color.hard));
				break;
			}
			default:
			{
				break;
			}
		}
    	
    }
    
    public void setView_Time()
    {
   		long currentTime;
		long differTime;
		long nHour;
		long nMin;
		long nSec;
		long nMSec;
		
		String strPlayTime;
		
    	TextView timeView = (TextView) this.findViewById(R.id.Result_TextView_Time);

		currentTime	= System.currentTimeMillis();
		differTime	= NGInfo.mTime_Finish-NGInfo.mTime_Start;
		
		nHour	= (differTime%ONE_DAY)/ONE_HOUR;
		nMin	= (differTime%ONE_HOUR)/ONE_MIN;
		nSec	= (differTime%ONE_MIN)/ONE_SEC;
		nMSec	= differTime%ONE_SEC;
		
		//Log.i("DBG", "[Listener_ChronometerTick]onChronometerTick"+" nHour:"+nHour+" nMin:"+nMin+" nSec:"+nSec+" nMSec:"+nMSec);
		
		strPlayTime	= String.format("%02d:%02d:%02d.%03d", nHour, nMin, nSec, nMSec);
		timeView.setText(strPlayTime);            	
    	
    }
    
    public void setView_Incorrect()
    {
    	String strIncorrectCount = String.format("%03d", NGInfo.mIncorrect);
    	TextView incorrectView = (TextView) this.findViewById(R.id.Result_TextView_Incorrect);

    	incorrectView.setText(strIncorrectCount);

    	
    }
    
}
